#在project()前设置，子项目使用，同样需要设置
if (POLICY CMP0091)
    cmake_policy(SET CMP0091 NEW)
else(POLICY CMP0091)
     #cmake 3.14以及以前版本设置方式 msvc 默认使用/MD
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif (POLICY CMP0091)

#编译时生成汇编文件。所有配置的工程都应用变量CMAKE_CXX_FLAGS进行配置
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FAs") 
#修改默认的RELWITHDEBINFO的工程配置，去除C++优化
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /Od /Ob1 /RTC1")

#设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED true)
#debug模式下，二进制文件添加后缀，对于可执行文件无效。
set(CMAKE_DEBUG_POSTFIX "_d")

macro(UTF8_CODE_COMPILE tgt_name)
    #以utf-8编译字面量字符 编码MSVC要从vs2015 update 3开始支持
    target_compile_options(${tgt_name} PRIVATE "/utf-8")
    # 设置link的选项
    if(WIN32)
        set_target_properties(${tgt_name} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
    endif(WIN32)
    # 设置C++的选项
    target_compile_options(${tgt_name}
        PRIVATE
        $<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>
        $<$<C_COMPILER_ID:MSVC>:/source-charset:utf-8>)
endmacro(UTF8_CODE_COMPILE)

#----------------------------------------------------------------------
# 结合POLICY CMP0091 ToSee:line2
function(SET_MSVC_MT tgt_names)
    #set_target_properties(tgt_name PROPERIES )
    if(MSVC)
        message(STATUS "set msvc runtime library /MT") 
        set_property(TARGET ${tgt_names} PROPERTY
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") 
    endif(MSVC)
endfunction()

function(SET_MSVC_MD tgt_names)
    if(MSVC)
        message(STATUS "set msvc runtime library /MT") 
        set_property(TARGET ${tgt_names} PROPERTY
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")   
    endif(MSVC)       
endfunction(SET_MSVC_MD tgt_names)

# MultiThreaded         : MT
# MultiThreadedDLL      : MD
# MultiThreadedDebug    : MTd
# MultiThreadedDebugDLL : MDd
#参考链接
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#
# https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html

#---------------------------------------------------------------------------







